package com.chj.design.sk;

public class Code20_Interpreter2 {
	public static class Context {
		/**
		 * 内容 竖线| 分隔
		 */
		private String content;

		public Context(String content) {
			this.content = content;
		}

		public String getContent() {
			return content;
		}

		public void setContent(String content) {
			this.content = content;
		}
	}

	public interface EyeColor {
		void interpreter(Context context);
	}

	public static class KeZhenE implements EyeColor {
		@Override
		public void interpreter(Context context) {
			if (context.getContent().contains("左摆头")) {
				System.out.println("冲！");
			} else if (context.getContent().contains("右摆头")) {
				System.out.println("撤！");
			}
		}
	}

	public static class Wife implements EyeColor {
		@Override
		public synchronized void interpreter(Context context) {
			if (context.getContent().contains("座椅")) {
				System.out.println("生气！");
			} else if (context.getContent().contains("架子")) {
				System.out.println("开心！");
			}
		}
	}

	public static void main(String[] args) {
		EyeColor eyeColor = null;
		Context context = new Context("柯镇恶往左摆头 | 老婆坐在了架子上");
		String content = context.getContent();
		String[] strings = content.split("\\|");
		for (int i = 0; i < strings.length; i++) {
			String string = strings[i];
			context.setContent(string);
			if (string.contains("柯镇恶")) {
				eyeColor = new KeZhenE();
			} else if (string.contains("老婆")) {
				eyeColor = new Wife();
			}
			assert eyeColor != null;
			eyeColor.interpreter(context);
		}
	}
}
